import { RequestResources } from "@/api/My";
export const Resource = {
    state:{
        resourceList:[]
    },
    mutations: {
		SAVE_RESOURCE(state, resourceList) {
			state.resourceList = resourceList
		},
		CLEAR_RESOURCE(state) {
			state.resourceList = []
		}
	},
    actions:{
        saveResource({commit},roleId){
            // 调用资源接口获取资源
            RequestResources(roleId).then(data=>{
                let {resultCode,resultInfo} = data
                if(resultCode === 1){
                    let resources = resultInfo.resource 
                    // 清理resourceList
                    commit('CLEAR_RESOURCE')
                    //保存到store中
                    commit('SAVE_RESOURCE',resources)
                }
            })
        }
    }
}